﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using GBL.Repository.Resources;
using GBlason.Culture;
using GBlason.ViewModel.CoatOfArm;
using ResourceManager = System.Resources.ResourceManager;

namespace GBlason.ViewModel
{
    public class TinctureViewModel : EditableResourceViewModel, IEquatable<TinctureViewModel>
    {
        public TinctureViewModel()
        {
        }

        public Guid Identifier { get; set; }

        public TinctureType Type { get; set; }
        
        public String LocalizedName
        {
            get
            {
                var manager = new ResourceManager(typeof(BlasonVocabulary));
                var name = manager.GetString(Name);
                return name ?? Name;
            }
        }

        /// <summary>
        /// Gets or sets the color of the background. (For Single color based filling)
        /// </summary>
        /// <value>
        /// The color of the background.
        /// </value>
        public Color TinctureColor
        {
            get { return _tinctureColor; }
            set
            {
                if (_tinctureColor == value) return;
                _tinctureColor = value;
                OnPropertyChanged("Color");
                OnPropertyChanged("TinctureColor");
            }
        }

        private Color _tinctureColor;

        /// <summary>
        /// Gets or sets the color of the fur.
        /// </summary>
        /// <value>
        /// The color of the fur.
        /// </value>
        public FurViewModel FurColor { get { return _furColor;  } 
            set
            {
                if (_furColor == value) return;
                _furColor = value;
                OnPropertyChanged("Color");
                OnPropertyChanged("FurColor");
            }}

        private FurViewModel _furColor;

        /// <summary>
        /// Gets or sets the color. /!\ For the color the returned type is a <see cref="SolidColorBrush"/>, for the Furs the returned type is a <see cref="DrawingBrush"/>
        /// Always set the type of color BEFORE defining those values
        /// </summary>
        /// <value>
        /// The color.
        /// </value>
        /// <remarks></remarks>
        public Brush Color
        {
            get
            {
                if (Type == TinctureType.Furs)
                    return FurColor.ResultingBrush();
                return new SolidColorBrush(TinctureColor);
            }
        }

        /// <summary>
        /// Gets the color for small display.
        /// </summary>
        public Brush ColorForSmallDisplay
        {
            get
            {
                if (Type == TinctureType.Furs)
                    return FurColor.ResultingBrush(true);
                return new SolidColorBrush(TinctureColor);
            }
        }

        /// <summary>
        /// Used for empty elements iitialisations (as key in doctionary)
        /// </summary>
        public static readonly TinctureViewModel DefaultTincture = new TinctureViewModel
                                                         {
                                                             Type = TinctureType.ColourBasic,
                                                             TinctureColor = System.Windows.Media.Color.FromArgb(0, 0, 0, 0),
                                                             Name = BlasonVocabulary.TinctureNone
                                                         };

        public bool Equals(TinctureViewModel p)
        {
            // If parameter is null, return false.
            if (ReferenceEquals(p, null))
            {
                return false;
            }

            // Optimization for a common success case.
            if (ReferenceEquals(this, p))
            {
                return true;
            }

            // If run-time types are not exactly the same, return false.
            if (GetType() != p.GetType())
                return false;

            return (Identifier == p.Identifier);
        }


    }
}
